package com.yanqu.road.server.cmd.activity.goldingotfund;

import com.yanqu.road.exception.BusinessException;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.GoldIngotFundProto;
import com.yanqu.road.pb.activity.HsIslandProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.goldingotfund.GoldIngotFundModule;
import com.yanqu.road.server.gameplayer.module.activity.hsisland.HsIslandActivityModule;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

@CmdApi(reqMsg = GoldIngotFundProto.GoldIngotFundSignReqMsg.class, respMsg = GoldIngotFundProto.GoldIngotFundSignRespMsg.class)
@Cmd(code = Protocol.S_GOLD_INGOT_FUND_SIGN,desc = "元宝多多-签到")
public class GoldIngotFundSignCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        GoldIngotFundProto.GoldIngotFundSignReqMsg reqMsg = GoldIngotFundProto.GoldIngotFundSignReqMsg.parseFrom(packet.getBytes());
        GoldIngotFundProto.GoldIngotFundSignRespMsg.Builder respMsg = GoldIngotFundProto.GoldIngotFundSignRespMsg.newBuilder();
        try {
            Property reward = player.getModule(GoldIngotFundModule.class).sign(reqMsg.getActivityId(), reqMsg.getDay());
            respMsg.setRet(0);
            respMsg.setReward(PropertyHelper.parsePropertyToString(reward));
        } catch (BusinessException e) {
            respMsg.setRet(e.getCode());
        }
        player.sendPacket(Protocol.U_GOLD_INGOT_FUND_SIGN, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {}
}
